
//
// BaseCustomNavView.m
//  v8090Video
//
//  Created by 陈建 on 2018/8/10.
//  Copyright © 2018年 BlueWind. All rights reserved.
//

#import "BaseCustomNavView.h"

@interface BaseCustomNavView ()
@property (nonatomic, strong) UIButton *leftBtn;
@property (nonatomic, strong) UIView *lineView;


@end

@implementation BaseCustomNavView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.isHiddenLeftBtn = NO;
        self.isHiddenLineView = NO;
        [self setupUI];
    }
    return self;
}

- (void)setIsHiddenLineView:(BOOL)isHiddenLineView{
    _isHiddenLineView = isHiddenLineView;
    self.lineView.hidden = isHiddenLineView;
}

- (void)setIsHiddenLeftBtn:(BOOL)isHiddenLeftBtn{
    _isHiddenLeftBtn = isHiddenLeftBtn;
    self.leftBtn.hidden = isHiddenLeftBtn;
}

- (void)setupUI{
    CGFloat topMagin = Height_StatusBar;
    CGFloat bottomHeight = Height_NavContentBar;
    
    [self.backimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backimageView);
        make.width.equalTo(@(bottomHeight));
        make.bottom.equalTo(self.backimageView);
        make.top.equalTo(@(topMagin));
    }];
    
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.backimageView);
        make.top.equalTo(@(topMagin));
        make.bottom.equalTo(self.backimageView);
    }];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(topMagin));
        make.bottom.equalTo(self.backimageView);
        make.right.equalTo(self.backimageView).offset(-GAP8);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.backimageView);
        make.left.right.equalTo(self.backimageView);
        make.height.equalTo(@0.5);
    }];
    
    
}

- (void)setBackImageViewColor:(UIColor *)backImageViewColor{
    _backImageViewColor = backImageViewColor;
     UIImage *img  = [UIImage imageWithColor:backImageViewColor withRect:self.frame];
    self.backimageView.image = img;
    

}

- (void)setupBackImageViewAlffectWithAlpha:(CGFloat)alpha{
    UIImage *img  = [UIImage imageWithColor:kRGBAColor(68, 119, 196, alpha) withRect:self.frame];
    self.backimageView.image = img;
}
    


- (void)setTitle:(NSString *)title{
    _title = title;
    self.titleLable.text = title;
}

- (void)setRightBtnTitle:(NSString *)rightBtnTitle{
    _rightBtnTitle = rightBtnTitle;
    [self.rightBtn setTitle:rightBtnTitle forState:UIControlStateNormal];
}



- (UILabel *)titleLable{
    if (!_titleLable) {
        _titleLable = [[UILabel alloc] init];
        _titleLable.font = [UIFont systemFontOfSize:15.f];
        _titleLable.textColor = [UIColor whiteColor];
        _titleLable.textAlignment = NSTextAlignmentCenter;
        [self.backimageView addSubview:_titleLable];
    }
    return _titleLable;
}

- (UIButton *)leftBtn{
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftBtn setImage:[UIImage imageNamed:@"Common_back_n"] forState:UIControlStateNormal];
        [_leftBtn setImage:[UIImage imageNamed:@"Common_back_n"] forState:UIControlStateSelected];
        
        [_leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backimageView addSubview:_leftBtn];
    }
    return _leftBtn;
}

- (void)leftBtnClick{
    if ([self.delegate respondsToSelector:@selector(tapCustomNavLeftBtnClick)]) {
        [self.delegate tapCustomNavLeftBtnClick];
    }
}

- (UIButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rightBtn.titleLabel.font = [UIFont systemFontOfSize:12.f];
        [_rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backimageView addSubview:_rightBtn];
    }
    return _rightBtn;
}

- (void)rightBtnClick{
    if ([self.delegate respondsToSelector:@selector(tapCustomNavRightBtnClick)]) {
        [self.delegate tapCustomNavRightBtnClick];
    }
}

- (UIImageView *)backimageView{
    if (!_backimageView) {
        _backimageView = [[UIImageView alloc] init];
        _backimageView.userInteractionEnabled = YES;
        UIImage *img  = [UIImage imageWithColor:[UIColor whiteColor] withRect:self.frame];
        _backimageView.image = img;
        [self addSubview:_backimageView];
    }
    return _backimageView;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor grayColor];
        [self.backimageView addSubview:_lineView];
    }
    return _lineView;
}




@end
